<?php
namespace app\index\controller;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");

use app\common\controller\HomeBase;

use think\Db;

class Finance extends HomeBase
{
	protected function _initialize(){
		parent::_initialize();
	}

	/**
	*金融显示页面
	*@param  int id 		  金融的id   
	**/
	public function show()
	{
		$id = $_GET['id'];
		$list = Db('nav')->where('pid',$id)->select();
		if($list){
            $this->apiSuccess($list);
        }else{
            $this->apiError('没有查到信息');
        }
	}


	/**
	*金融添加操作
	*@param  int id 		  金融的id
	*@param  int nav_id 	  金融下购车分期的id      
	**/
	public function informationAdd()
	{
		//接收参数
		$classifyID = $_POST['id'];
		$nav_id = $_POST['nav_id'];
		$reservedName = htmlspecialchars($_POST['name']);
		$reservedPhone = htmlspecialchars($_POST['phone']);

		//判断该手机号是否申请过
		$number = Db('reserved')->where('nav_id',$nav_id)->where('reservedPhone',$reservedPhone)->find();
		if ($number) {
			$this->apiError('已申请,请您耐心等待');
			die;
		}

		$create_time = date('Y-m-d H:i:s',strtotime('now'));
		$data = [
			'classifyID' => $classifyID,
			'nav_id' => $nav_id,
			'reservedName' => $reservedName,
			'reservedPhone' => $reservedPhone,
			'reservedDate' => $create_time
		];
		$add = Db('reserved')->insert($data);
		if($add){
			//查询电话号码
			$phoneList = Db('system')->select();
			$value = unserialize($phoneList[0]['value']);
			$arr[] = $value['site_phone'];
			$this->apiSuccess($arr,'添加成功');
		}else{
			$this->apiError('添加失败,请重试');
		}
	}
}